package cn.witsky.rtp2ws.util;

public class RtpUtil {

	static int mergeByte2Hex(byte high, byte low) {
		return (high & 0xFF) << 8 | low & 0xFF;
	}
	
	
	public static int getSeq(byte[] bytes) {
		if(bytes.length<4) {
			return -1;
		}else {
			byte high=bytes[2];
			byte low=bytes[3];
			return (high & 0xFF) << 8 | low & 0xFF;
		}		
	}
	public static int getTimeStamp(byte[] bytes) {
		if(bytes.length<8) {
			return -1;
		}else {
			int v0 = (bytes[4] & 0xff) << 24;//&0xff将byte值无差异转成int,避免Java自动类型提升后,会保留高位的符号位
			int v1 = (bytes[5] & 0xff) << 16;
			int v2 = (bytes[6] & 0xff) << 8;
			int v3 = (bytes[7] & 0xff) ;
			return v0 + v1 + v2 + v3;
		}		
	}
	public static String byte2Hex(byte[] bytes) {
		StringBuffer stringBuffer = new StringBuffer();
		String temp = null;
		for (int i = 0; i < bytes.length; i++) {
			temp = Integer.toHexString(bytes[i] & 0xFF);
			if (temp.length() == 1) {
// 1得到一位的进行补0操作
				stringBuffer.append("0");
			}
			stringBuffer.append(temp);
		}
		return stringBuffer.toString();
	}
}
